package com.example.jegotrip.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.jegotrip.R;
import com.example.jegotrip.base.BaseActivity;
import com.example.jegotrip.db.UserDBHelper;
import com.example.jegotrip.utils.CustomToast;

public class RegisterActivity extends BaseActivity {

    private EditText et_username;
    private EditText et_password;
    private Button      et_signBtn;
    private Button      backLoginBtn;

    @Override
    protected void initData() {

    }

    @Override
    protected void setListener() {
        findViewById(R.id.SignUpButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String username = et_username.getText().toString();
                String password = et_password.getText().toString();
                if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
                    CustomToast.showCenterToast(RegisterActivity.this, "请输入用户名或密码");
                } else {
                    int res = UserDBHelper.getInstance(RegisterActivity.this).register(username, password, "这个家伙很懒，神吗东西没留下", '1');
                    if (res > 0) {
                        CustomToast.showCenterToast(RegisterActivity.this, "注册成功，请登录");
                        //回到登录页面
//                        finish();
                    } else {
                        CustomToast.showCenterToast(RegisterActivity.this, "注册失败");
                    }
                }
            }
        });

        findViewById(R.id.BackLoginButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    protected void initViews() {
        et_username = findViewById(R.id.et_username);
        et_password = findViewById(R.id.et_password);
        et_signBtn = findViewById(R.id.SignUpButton);
        backLoginBtn = findViewById(R.id.BackLoginButton);
    }

    @Override
    protected int getLayoutResOId() {
        return R.layout.activity_sign_up;
    }
}
